package com.ruoyi.service.contract.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.uuid.UUID;
import com.ruoyi.service.contract.domain.ContractInfo;
import com.ruoyi.service.contract.mapper.ContractInfoMapper;
import com.ruoyi.service.contract.service.IContractInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * contractService业务层处理
 * 
 * @author zhangpu
 * @date 2024-04-17
 */
@Service
public class ContractInfoServiceImpl implements IContractInfoService 
{
    @Autowired
    private ContractInfoMapper contractInfoMapper;

    /**
     * 查询contract
     * 
     * @param id contract主键
     * @return contract
     */
    @Override
    public ContractInfo selectContractInfoById(String id)
    {
        return contractInfoMapper.selectContractInfoById(id);
    }

    /**
     * 查询contract列表
     * 
     * @param contractInfo contract
     * @return contract
     */
    @Override
    public List<ContractInfo> selectContractInfoList(ContractInfo contractInfo)
    {
        return contractInfoMapper.selectContractInfoList(contractInfo);
    }

    /**
     * 新增contract
     * 
     * @param contractInfo contract
     * @return 结果
     */
    @Override
    public int insertContractInfo(ContractInfo contractInfo)
    {
        contractInfo.setCreateTime(DateUtils.getNowDate());
        contractInfo.setId(StringUtils.replace(UUID.randomUUID().toString(),"-",""));

        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        int nextInt = rnd.nextInt(999999);
        if (nextInt < 100000) {
            nextInt = rnd.nextInt(999999);
        }
        contractInfo.setContractNo("CQ_CON"+ DateUtils.dateTime()+nextInt);
        return contractInfoMapper.insertContractInfo(contractInfo);
    }

    /**
     * 修改contract
     * 
     * @param contractInfo contract
     * @return 结果
     */
    @Override
    public int updateContractInfo(ContractInfo contractInfo)
    {
        return contractInfoMapper.updateContractInfo(contractInfo);
    }

    /**
     * 批量删除contract
     * 
     * @param ids 需要删除的contract主键
     * @return 结果
     */
    @Override
    public int deleteContractInfoByIds(String[] ids)
    {
        return contractInfoMapper.deleteContractInfoByIds(ids);
    }

    /**
     * 删除contract信息
     * 
     * @param id contract主键
     * @return 结果
     */
    @Override
    public int deleteContractInfoById(String id)
    {
        return contractInfoMapper.deleteContractInfoById(id);
    }
}
